package com.dstz.demo.rest.controller;

import com.dstz.base.api.aop.annotion.CatchErr;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.rest.BaseController;
import com.dstz.demo.core.manager.CollectionlistManager;
import com.dstz.demo.core.model.Collectionlist;
import com.dstz.sys.util.ContextUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sys/collectionlist")
public class CollectionlistController extends BaseController<Collectionlist> {
    @Resource
    CollectionlistManager collectionlistManager;

    @Override
    protected String getModelDesc() {
        return null;
    }

    @PostMapping("/save/{id}")
    @CatchErr(write2response = true, value = "查询信息失败")
    public ResultMsg saves(@PathVariable("id") String id) {
        String[] ids = id.split(",");
        for (int i = 0; i < ids.length; i++) {
            List<Collectionlist> list = collectionlistManager.findById(ids[i]);
            if (list.size() == 0) {
                Collectionlist collectionlist = new Collectionlist();
                collectionlist.setServicesid(ids[i]);
                collectionlist.setUserid(ContextUtil.getCurrentUserId());
                collectionlist.setProjectsid("1");
                collectionlistManager.save(collectionlist);
            }
            continue;
        }
        return getSuccessResult("收藏成功");
    }
}
